import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
        name: 'welcome',
        component: () => import('@/views/login/welcome'),
        meta: {
          title: "欢迎"
        }
  },
  {
    path: '',
    name: '',
    component: () => import('@/views/layout/layout'),
    children: [
      {
        path: '/Home',
        name: 'Home',
        component: Home,
        meta: {
          title: "首页"
        },
      },
      {
        path: '/community',
        name: 'community',
        component: () => import('@/views/community/community'),
        meta: {
          title: "社区"
        },
      },
      {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my/my'),
        meta: {
          title: "我的"
        },
      },
      {
        path: '/classification',
        name: 'classification',
        component: () => import('@/views/home/classification/classification'),
        meta: {
          title: "精选"
        },
      },
    ]
  },
  {
    path: '/Publishpage1',
        name: 'Publishpage1',
        component: () => import('@/views/community/Publishpage/Publishpage1'),
        meta: {
          title: "项目选择"
        }
  },
  {
    path: '/Publishpage2',
        name: 'Publishpage2',
        component: () => import('@/views/community/Publishpage/Publishpage2'),
        meta: {
          title: "医生选择"
        }
  },
  {
    path: '/Publishisend',
        name: 'Publishisend',
        component: () => import('@/views/community/Publishpage/Publishisend'),
        meta: {
          title: "发送日志"
        }
  },
  {
    path: '/register',
        name: 'register',
        component: () => import('@/views/register/register'),
        meta: {
          title: "注册"
        }
  },
  {
    path: '/login',
        name: 'login',
        component: () => import('@/views/login/login'),
        meta: {
          title: "登录"
        }
  },
  {
    path: '/my/Sign',
        name: 'Sign',
        component: () => import('@/views/my/Sign/Sign'),
        meta: {
          title: "签到"
        }
  },
  {
    path: '/my/setup',
        name: 'setup',
        component: () => import('@/views/my/setup/setup'),
        meta: {
          title: "设置"
        }
  },
  {
    path: '/my/Contact',
        name: 'Contact',
        component: () => import('@/views/my/Contact/Contact'),
        meta: {
          title: "联系客服"
        }
  },
  {
    path: '/my/order',
        name: 'order',
        component: () => import('@/views/my/order/order'),
        meta: {
          title: "我的订单"
        }
  },
  {
    path: '/my/order2',
        name: 'order2',
        component: () => import('@/views/my/order/order2'),
        meta: {
          title: "我的订单2"
        }
  },
  {
    path: '/my/news',
        name: 'news',
        component: () => import('@/views/my/news/news'),
        meta: {
          title: "消息中心"
        }
  },
  {
    path: '/my/address',
        name: 'address',
        component: () => import('@/views/my/address/address'),
        meta: {
          title: "地址管理"
        }
  },
  {
    path: '/my/add_address',
        name: 'add_address',
        component: () => import('@/views/my/address/add_address'),
        meta: {
          title: "新增地址"
        }
  },
  {
    path: '/my/child/Collection',
        name: 'Collection',
        component: () => import('@/views/my/child/Collection'),
        meta: {
          title: "收藏"
        }
  },
  {
    path: '/my/child/coupon',
        name: 'coupon',
        component: () => import('@/views/my/child/coupon'),
        meta: {
          title: "优惠券"
        }
  },
  {
    path: '/my/child/Cdiary',
        name: 'diary',
        component: () => import('@/views/my/child/diary'),
        meta: {
          title: "日记"
        }
  },
  {
    path: '/my/child/integral',
        name: 'integral',
        component: () => import('@/views/my/child/integral'),
        meta: {
          title: "积分"
        }
  },
  {
    path: '/details/commodityDetails',
        name: 'commodityDetails',
        component: () => import('@/views/details/commodityDetails'),
        meta: {
          title: "商品详情"
        }
  },
  {
    path: '/details/hospitaldetail',
        name: 'hospitaldetail',
        component: () => import('@/views/details/hospitaldetail'),
        meta: {
          title: "医院详情"
        }
  },
  {
    path: '/details/doctorDetails',
        name: 'doctorDetails',
        component: () => import('@/views/details/doctorDetails'),
        meta: {
          title: "医生详情"
        }
  },
  {
    path: '/details/journaldetail',
        name: 'ordjournaldetail',
        component: () => import('@/views/details/journaldetail'),
        meta: {
          title: "日志详情"
        }
  },
  {
    path: '/details/commodityDetails/Confirmorder',
        name: 'Confirmorder',
        component: () => import('@/views/details/Confirmorder'),
        meta: {
          title: "确认订单"
        }
  },
  {
    path: '*',
        name: 'Notfound',
        component: () => import('@/views/Notfound/Notfound'),
        meta: {
          title: "404"
        }
  },
]

const router = new VueRouter({
  mode: 'history', //hash
  base: process.env.BASE_URL,
  routes
})


const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

router.beforeEach((to, from, next) => {
  document.title = to.meta.title; //动态改变浏览器标题
  next()
  // if (to.path === "/login") {
  //   //当进入的就是登陆页面或者注册页面时，不做操作
  //   next();
  // } else {
  //   if (sessionStorage.getItem("token")) {
  //     //同过登陆成功时存储在本地用户名，来判断用户是否成功登陆
  //     next();
  //   } else {
  //     next("/login");
  //   }
  // }
});

export default router
